<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>diff_as_string (Spec::Expectations::Differs::Default)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File vendor\plugins\rspec/lib/spec/expectations/differs/default.rb, line 24</span>
        <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">diff_as_string</span>(<span class="ruby-identifier">data_old</span>, <span class="ruby-identifier">data_new</span>)
          <span class="ruby-identifier">data_old</span> = <span class="ruby-identifier">data_old</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/\n/</span>).<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">chomp</span> }
          <span class="ruby-identifier">data_new</span> = <span class="ruby-identifier">data_new</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/\n/</span>).<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">chomp</span> }
          <span class="ruby-identifier">output</span> = <span class="ruby-value str">&quot;&quot;</span>
          <span class="ruby-identifier">diffs</span> = <span class="ruby-constant">Diff</span><span class="ruby-operator">::</span><span class="ruby-constant">LCS</span>.<span class="ruby-identifier">diff</span>(<span class="ruby-identifier">data_old</span>, <span class="ruby-identifier">data_new</span>)
          <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">output</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">diffs</span>.<span class="ruby-identifier">empty?</span>
          <span class="ruby-identifier">oldhunk</span> = <span class="ruby-identifier">hunk</span> = <span class="ruby-keyword kw">nil</span>  
          <span class="ruby-identifier">file_length_difference</span> = <span class="ruby-value">0</span>
          <span class="ruby-identifier">diffs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">piece</span><span class="ruby-operator">|</span>
            <span class="ruby-keyword kw">begin</span>
              <span class="ruby-identifier">hunk</span> = <span class="ruby-constant">Diff</span><span class="ruby-operator">::</span><span class="ruby-constant">LCS</span><span class="ruby-operator">::</span><span class="ruby-constant">Hunk</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">data_old</span>, <span class="ruby-identifier">data_new</span>, <span class="ruby-identifier">piece</span>, <span class="ruby-ivar">@context_lines</span>,
                                         <span class="ruby-identifier">file_length_difference</span>)
              <span class="ruby-identifier">file_length_difference</span> = <span class="ruby-identifier">hunk</span>.<span class="ruby-identifier">file_length_difference</span>      
              <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">oldhunk</span>      
              <span class="ruby-comment cmt"># Hunks may overlap, which is why we need to be careful when our</span>
              <span class="ruby-comment cmt"># diff includes lines of context. Otherwise, we might print</span>
              <span class="ruby-comment cmt"># redundant lines.</span>
              <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@context_lines</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">hunk</span>.<span class="ruby-identifier">overlaps?</span>(<span class="ruby-identifier">oldhunk</span>)
                <span class="ruby-identifier">hunk</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">oldhunk</span>)
              <span class="ruby-keyword kw">else</span>
                <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">oldhunk</span>.<span class="ruby-identifier">diff</span>(<span class="ruby-ivar">@format</span>)
              <span class="ruby-keyword kw">end</span>
            <span class="ruby-keyword kw">ensure</span>
              <span class="ruby-identifier">oldhunk</span> = <span class="ruby-identifier">hunk</span>
              <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
            <span class="ruby-keyword kw">end</span>
          <span class="ruby-keyword kw">end</span>  
          <span class="ruby-comment cmt">#Handle the last remaining hunk</span>
          <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">oldhunk</span>.<span class="ruby-identifier">diff</span>(<span class="ruby-ivar">@format</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
        <span class="ruby-keyword kw">end</span></pre>
</body>
</html>